//
//  buttonOfTableViewController.m
//  mintHome
//
//  Created by 朱彦名 on 16/6/24.
//  Copyright © 2016年 朱彦名. All rights reserved.
//

#import "buttonOfTableViewController.h"
#import "cellOfFirst.h"
#import "modelOfMintHome.h"
#import "viewOfTag.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "APPTools.h"
#import "webViewOfBottom.h"

@interface buttonOfTableViewController ()
@property (nonatomic, retain) NSMutableArray *arrOfSec;
@property (nonatomic, retain) NSMutableArray *arrOfData;


@end

@implementation buttonOfTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView registerClass:[cellOfFirst class] forCellReuseIdentifier:@"pool"];
    [self handleData];

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _arrOfSec.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    cellOfFirst *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    
    BOOL model = [AccountManager sharedInstance].isNight;
    if (model) {
        cell.backgroundColor = [UIColor silverColor];
        
    }else{
        cell.backgroundColor = [UIColor whiteColor];
    }
    
    modelOfMintHome *model1 = _arrOfSec[indexPath.row];
    cell.labelOfTitle.text = model1.title;
    [cell.imageOfMint sd_setImageWithURL:[NSURL URLWithString:model1.cover_image_url]];
    cell.viewOfTag.labelOfTag.text = [NSString stringWithFormat:@"%ld",model1.likes_count];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
- (void)handleData{
    self.arrOfData = [NSMutableArray array];
    self.arrOfSec = [NSMutableArray array];
    
    [MBProgressHUDManager showHUDtoView:self.tableView string:@"正在加载"];
    
        [APPTools GETWithURL:_urlRe par:nil success:^(id responseObject) {
            
            self.arrOfData = responseObject [@"data"][@"posts"];
            
            self.arrOfSec = [modelOfMintHome modelHandlerWithArray:self.arrOfData];
            
            [self.tableView reloadData];
            [MBProgressHUDManager removeHUD];
            
        } filed:^(NSError *error) {
            
        }];
    

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    webViewOfBottom *webView = [[webViewOfBottom alloc]init];
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dic in self.arrOfData) {
        [arr addObject:[dic objectForKey:@"url"]];
        
    }
    webView.url2 = arr[indexPath.row];
    [self.navigationController pushViewController:webView animated:YES];
    
}

- (void)setLightDay{
    [NightManager setBackgroundColorWithView:self.view];
    [self.tableView reloadData];
    
}
- (void)setNightDay{
    [NightManager setBackgroundColorWithView:self.view];
    [self.tableView reloadData];
    
}

@end
